package 数据库连接池;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;

public class C3P0Test {
    /**
     *      c3p0待解决!!!!!!
     * @throws Exception
     */
    //方式一：
    @Test
    public void testGetConnection1() throws Exception {
        //获取c3p0数据库连接池
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
        cpds.setJdbcUrl( "jdbc:mysql://localhost:3306/xclmf" );
        cpds.setUser("root");
        cpds.setPassword("552200");
        //设置初始时数据库连接池中的连接数
        cpds.setInitialPoolSize(10);
        //获取数据库连接
        Connection connection = cpds.getConnection();
        System.out.println(connection);
        //销毁连接池
        //DataSources.destroy(cpds);
    }

    //方式二：使用配置文件
    @Test
    public void testGetConnection2() throws SQLException {
        ComboPooledDataSource cpds = new ComboPooledDataSource("c3p0-config.xml");
        Connection connection = cpds.getConnection();
        System.out.println(connection);
    }
}
